package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityQueryVO;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityVO;
import com.minimalist.common.feign.client.lindi.LindiActivityFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地活动 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiActivityFeignClientFallbackFactory extends BaseFallbackFactory<LindiActivityFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiActivityFeignClientFallbackFactory.class);


    @Override
    public LindiActivityFeignClient create(Throwable cause) {
        return new LindiActivityFeignClient() {
            @Override
            public R<?> addActivity(LindiActivityVO activityVO) {
                logServiceUnavailable("添加活动", activityVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "添加活动失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateActivityByActivityId(LindiActivityVO activityVO) {
                logServiceUnavailable("修改活动", activityVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "修改活动失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteActivityByActivityId(Long activityId) {
                logServiceUnavailable("删除活动", activityId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "删除活动失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiActivityVO> getActivityByActivityId(Long activityId) {
                logServiceUnavailable("获取活动详情", activityId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "获取活动详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiActivityVO>> getPageActivityList(LindiActivityQueryVO queryVO) {
                logServiceUnavailable("分页查询活动列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), 
                        "分页查询活动列表失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
